﻿#coding=utf-8
#Boa:PopupTransientWindow:PopupTWinCustomer


import wx
from product import *
from MyListCtrl import *
from config import *
from singleton import *

def create(parent):
    return PopupTWinCustomer(parent)

[wxID_POPUPTWINCUSTOMER] = [wx.NewId() for _init_ctrls in range(1)]

class PopupTWinCustomer(wx.PopupTransientWindow):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.PopupTransientWindow.__init__(self, parent=prnt,
              style=wx.SIMPLE_BORDER)
        self.SetSize(wx.Size(600, 400))
        self.Move(wx.Point(400, 235))
        self.SetName(u'PopupTWinCustomer')

    def __init__(self, parent):
        self._init_ctrls(parent)
        #self.parent = parent
        self.myInit()
        
    def myInit(self):
        self.SetSize(wx.Size(600, 400))
        
##        self.listCtrl = MyListCtrl(parent=self, cols=Cfg.getCustPopupColsMode(),
##                                    clsDataModel=CDataCustomer)
        self.listCtrl = MyCustomerListCtrl(self)
        self.listCtrl.SetSize(wx.Size(600, 400))
        self.listCtrl.Move(wx.Point(0, 0))
        self.listCtrl.refresh()
        
        self.listCtrl.Bind(wx.EVT_LEFT_DCLICK, self.OnSelectCustomer)
      

##    def OnPopupTWinCustomerPaint(self, event):
##        print 'OnPopupTWinCustomerPaint'
##        CDataCustomer.alterCols(Cfg.getCustPopupColsText())
##        event.Skip()

    def setFilter(self, str):
        self.listCtrl.refresh({'all':str})

    def OnSelectCustomer(self, event):
        print 'OnSelectCustomer'
        item = self.listCtrl.GetNextItem(-1, state = wx.LIST_STATE_SELECTED)
        if (item == -1):
            return
        
        fields = {'id':self.listCtrl.GetItemText(item)}
        self.GetParent().setCustomer(CDataCustomer.getData(fields))
        #self.Destroy()
        self.Dismiss()
        #self.Show(False)

